package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.GoodsAreaService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 区域商品库存控制层|路由层
 * @作者 李宇鹏
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-04-18 09:19:30
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/goodsArea")
public class GoodsAreaController{

  private final GoodsAreaService goodsAreaService;

  public GoodsAreaController(final GoodsAreaService goodsAreaService){
    this.goodsAreaService = goodsAreaService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('inventory_manage_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.add(request),response);
  }

  /**行内编辑 更改库存*/
  @PreAuthorize("hasAuthority('inventory_manage_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.edit(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('inventory_manage_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.queryById(id),response);
  }

  /**获取操作记录列表*/
  @PreAuthorize("hasAuthority('inventory_manage_row_record')")
  @GetMapping("/getRecord")
  public void getRecord(final Long kid,final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.getRecord(kid),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('inventory_manage_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.listData(new PageFormData(request)),response);
  }

  //获取表goods_area的字段goods_id的下拉框列动态值选项的数据
  @PreAuthorize("hasAuthority('inventory_manage_btn_goods_id')")
  @GetMapping("/getGoods_id")
  public void getGoods_id(final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.getGoods_id(),response);
  }

  //获取表goods_area的字段user_id的下拉框列动态值选项的数据
  @PreAuthorize("hasAuthority('inventory_manage_btn_user_id')")
  @GetMapping("/getUser_id")
  public void getUser_id(final HttpServletResponse response){
    ToolClient.responseJson(goodsAreaService.getUser_id(),response);
  }
}